package lk.icta.core.entity;

import lk.icta.common.entity.Person;

import javax.persistence.*;
import java.io.Serializable;

@Entity
@Table(schema = "ELAND_RAIL")
@NamedQueries({
        @NamedQuery(name = "getORMOIByOrganizationId", query = "SELECT u FROM URMGOIUser u WHERE u.organization.id = :organizationId"),
        @NamedQuery(name = "getORMOIByUserName", query = "SELECT u FROM URMGOIUser u WHERE u.username = :username")

})
public class URMGOIUser implements Serializable {


    public enum State {
        /**
         * 0 - A active organization
         */
        ACTIVE,
        /**
         * 1 - a inactive organization
         */
        INACTIVE

    }

    /**
     * A system generated unique key
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;

    /**
     * URMGOI userName
     */
    @Column(length = 30)
    private String username;

    /**
     * Details of the UR-MGOI User
     */
    @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE})
    @JoinColumn(nullable = false)
    private Person userDetail;

    @ManyToOne
    @JoinColumn(nullable = true)
    private Organization organization;

    @Enumerated
    private State status;

    @Embedded
    private LifeCycleInfo lifeCycleInfo = new LifeCycleInfo();

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }


    public Person getUserDetail() {
        return userDetail;
    }

    public void setUserDetail(Person userDetail) {
        this.userDetail = userDetail;
    }

    public Organization getOrganization() {
        return organization;
    }

    public void setOrganization(Organization organization) {
        this.organization = organization;
    }

    public State getStatus() {
        return status;
    }

    public void setStatus(State status) {
        this.status = status;
    }

    public LifeCycleInfo getLifeCycleInfo() {
        return lifeCycleInfo;
    }

    public void setLifeCycleInfo(LifeCycleInfo lifeCycleInfo) {
        this.lifeCycleInfo = lifeCycleInfo;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }
}
